import create from '../../utils/create2.js'
import store from '../../store/index.js'
let plugin = requirePlugin('routePlan');
create(store,{

  /**
   * 页面的初始数据
   */
  data: {
    store: {},
    markers: [],
    mapKey:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.$http().request({ url: '/AppMaster/AgentUnion/myShopAgentInfo', method: 'POST' }).then(res => {
      const { _data } = res
      const { data } = _data
      let markers = [{
        iconPath: "../../asset/icon/position.png",
        latitude: data.latitude,
        longitude: data.longitude,
        width:40,
        height:40,
        callout:{
          content: data.address,
          bgColor:'#ffffff',
          borderRadius:5,
          padding:5,
          display:'ALWAYS'
        }
      }]
      this.setData({
        store: data,
        markers
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
 routePlan() {
   const {store} = this.data
   const { route_plan_key, route_plan_referer, longitude, latitude, address} = store
   let endPoint = JSON.stringify({  //终点
     'name': address,
     'latitude': latitude,
     'longitude': longitude
   });
   wx.navigateTo({
     url: 'plugin://routePlan/index?key=' + route_plan_key + '&referer=' + route_plan_referer + '&endPoint=' + endPoint
   });
 }
})